import java.io.*;
import java.net.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class RaxiKlient extends Applet implements Runnable, ActionListener{
	TextArea ta=new TextArea();
	TextField tf=new TextField();
	RaxiRuudustik ruudustik=new RaxiRuudustik();
	Socket sc;
	PrintWriter pw;
	BufferedReader br;
	
	public static final long serialVersionUID=1;
	public RaxiKlient(){
		setLayout(new BorderLayout());
		Panel p=new Panel(new GridLayout(2, 1));
		p.add(ta);
		p.add(ruudustik);
		add(p, BorderLayout.CENTER);
		add(tf, BorderLayout.SOUTH);
		tf.addActionListener(this);
		try{
			sc=new Socket("greeny.cs.tlu.ee", 4407);
			pw=new PrintWriter(sc.getOutputStream(), true);
			br=new BufferedReader(new InputStreamReader(sc.getInputStream()));
		} catch(Exception e){e.printStackTrace();}
		new Thread(this).start();
	}
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==tf){
			pw.println(tf.getText());
			tf.setText("");
		}
	}
	public void run(){
		try{
		String rida=br.readLine();
		while(rida!=null){
			ta.append(rida+"\n");
			rida=br.readLine();
		}
	 } catch(Exception e){e.printStackTrace();}
	 ta.append("ots");
	}
}




